package com.evry.spring3sandbox.oxm;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.evry.spring3sandbox.oxm.marshaller.Jaxb2Marshaller;
import com.evry.spring3sandbox.oxm.marshaller.Marshaller;
import com.evry.spring3sandbox.oxm.model.Customers;
import com.evry.spring3sandbox.oxm.model.Database;
import com.evry.spring3sandbox.oxm.model.Products;
import com.evry.spring3sandbox.service.CustomerManager;
import com.evry.spring3sandbox.service.ProductManager;

public class JaxbApp {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext appContext =
	            new ClassPathXmlApplicationContext("App.xml");
	        Marshaller application = (Jaxb2Marshaller) appContext.getBean("marshaller");
	        ProductManager productManager = (ProductManager) appContext.getBean("productManager");
	        Database database = new Database();
	        Products products = new Products();
	        products.setProduct(productManager.getProducts());
	        database.setProducts(products);
	        
	        CustomerManager customerManager = (CustomerManager) appContext.getBean("customerManager");
	        Customers customers = new Customers();
	        customers.setCustomer(customerManager.getCustomers());
	        database.setCustomers(customers);
	        
	        System.out.println(application.marshal(database));
	        
	        String string = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
	        		"<Database xmlns=\"http://www.spring3sandbox.com/model\"></Database>";
	        //<Products><Product><id>1</id><description>Cheap</description><price>2.9</price><name>Smart Starter</name><storageSpace>512MB</storageSpace><bandwidth>50GB</bandwidth><sqldatabase>UNLIMITED</sqldatabase><setupfee>19.90$</setupfee></Product><Product><id>2</id><description>Cheap</description><price>5.9</price><name>Smart Medium</name><storageSpace>1GB</storageSpace><bandwidth>100GB</bandwidth><sqldatabase>UNLIMITED</sqldatabase><setupfee>12.90$</setupfee></Product><Product><id>3</id><description>Cheap</description><price>9.9</price><name>Smart Business</name><storageSpace>2GB</storageSpace><bandwidth>150GB</bandwidth><sqldatabase>UNLIMITED</sqldatabase><setupfee>FREE</setupfee></Product><Product><id>4</id><description>Cheap</description><price>14.9</price><name>Smart Deluxe</name><storageSpace>4GB</storageSpace><bandwidth>UNLIMITED</bandwidth><sqldatabase>UNLIMITED</sqldatabase><setupfee>FREE</setupfee></Product></Products></Database>

	        Object obj = application.unmarshal(string);
	}

}
